import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_elf/utils/navigator_utils.dart';
import 'package:flutter_elf/widgets/appbar_creator.dart';

import 'base_page_state.dart';

class MyPages extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return MyPagesState();
  }
}

class MyPagesState extends BasePageState<MyPages>{

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print('initState');
  }

  @override
  void dispose() {
    // TODO: implement dispose
    timer?.cancel();
    super.dispose();
    print('dispose');
  }
  Timer timer;
  @override
  void onResume() {
    // TODO: implement onResume
    super.onResume();
    print('onResume');
    timer = Timer.periodic(Duration(seconds: 1), (t){
      if(t.tick%4 == 1){
        viewState = ViewState.busy;
      }else if(t.tick%4 == 2){
        viewState = ViewState.success;
      }else if(t.tick%4 == 3){
        viewState = ViewState.error;
      }else{
        viewState = ViewState.idle;
      }
      setState(() {

      });
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBarCreator.create(context, '呵呵'),
      body: buildContent(Center(child: Text('加载成功')))
    );
  }
}
